﻿using Common;
using Core.CommandHandlers;
using Core.Commands.Exams;
using Database.Context;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Diagnostics;

namespace Core.Commands
{
    public class CommandBus: ICommandBus
    {
      
        
        public void Send<T>(T command) where T : ICommand
        {

            var startTime = DateTime.Now;
            var hanlder = GetServiceExtension.Services.GetService(typeof(ICommandHandler<T>)) as ICommandHandler<T>;

            hanlder.Execute(command);
            var endTime = DateTime.Now;
            Console.WriteLine((endTime - startTime).TotalSeconds.ToString("0.000"));
        }
    }
}
